#ifndef FUNC_H_INCLUDED
#define FUNC_H_INCLUDED

int init(){
    display = NULL;
    event_queue = NULL;
    event_queue2 = NULL;
    timer = NULL;


    if(!al_init()) {
      std::cout << "failed to initialize allegro!\n";
      return 0;
    }

    if(!al_install_keyboard()) {
        std::cout << "failed to initialize the keyboard!\n";
        return 0;
    }

     if(!al_install_mouse()) {
      fprintf(stderr, "failed to initialize the mouse!\n");
      return -1;
   }

    if(!al_init_image_addon()) {
      al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_image_addon!",
                                 NULL, ALLEGRO_MESSAGEBOX_ERROR);
      return 0;
    }

    timer = al_create_timer(1.0 / FPS);
    if(!timer) {
      std::cout << "failed to create timer!\n";
      return -1;
    }

    display = al_create_display(DISPLAY_W, DISPLAY_H);
    if(!display) {
      std::cout <<  "failed to create display!\n";
      return 0;
    }

    event_queue = al_create_event_queue();
    if(!event_queue) {
      std::cout << "failed to create event_queue!\n";
      al_destroy_display(display);
      al_destroy_timer(timer);
      return -1;
    }

     event_queue2 = al_create_event_queue();
    if(!event_queue2) {
      std::cout << "failed to create event_queue!\n";
      al_destroy_display(display);
      al_destroy_timer(timer);
      return -1;
    }

    al_init_font_addon(); // initialize the font addon
    al_init_ttf_addon();// initialize the ttf (True Type Font) addon

    al_register_event_source(event_queue, al_get_display_event_source(display));

    al_register_event_source(event_queue, al_get_timer_event_source(timer));

    al_register_event_source(event_queue, al_get_keyboard_event_source());

    al_register_event_source(event_queue, al_get_mouse_event_source());



    al_register_event_source(event_queue2, al_get_display_event_source(display));

    al_register_event_source(event_queue2, al_get_keyboard_event_source());

    al_register_event_source(event_queue2, al_get_mouse_event_source());

    return 1;
}

#endif // FUNC_H_INCLUDED
